package com.gwm.search.listener;

import com.gwm.search.service.SearchService;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.gwm.common.constants.RocketMQConstants.CONSUMER.ITEM_SEARCH_UP;
import static com.gwm.common.constants.RocketMQConstants.TAGS.ITEM_UP_TAGS;
import static com.gwm.common.constants.RocketMQConstants.TOPIC.ITEM_TOPIC_NAME;

@Component
@RocketMQMessageListener(consumerGroup=ITEM_SEARCH_UP,topic =ITEM_TOPIC_NAME,selectorExpression = ITEM_UP_TAGS,messageModel= MessageModel.BROADCASTING)
public class ItemUpListener implements RocketMQListener<Long> {

    @Autowired
    private SearchService searchService;

    @Override
    public void onMessage(Long spuId) {
        searchService.createOneIndex(spuId);
        System.out.println("索引文件生成成功.......上架.");

    }
}
